package com.nineclock.system.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.utils.BeanHelper;
import com.nineclock.system.dto.SysSalaryDTO;
import com.nineclock.system.mapper.SysSalaryMapper;
import com.nineclock.system.pojo.SysSalary;
import com.nineclock.system.service.SysSalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SysSalaryServiceimpl implements SysSalaryService {

    @Autowired(required = false)
    private SysSalaryMapper sysSalaryMapper;

    @Override
    public PageResult<SysSalaryDTO> queryCompanyUserSalary(Integer page, Integer pageSize) {

        IPage<SysSalary> ipage = new Page(page,pageSize);
        ipage = sysSalaryMapper.selectPage(ipage, null);
        List<SysSalaryDTO> sysSalaryDTOS = BeanHelper.copyWithCollection(ipage.getRecords(), SysSalaryDTO.class);
        return new PageResult<>(ipage.getTotal(),ipage.getPages(),sysSalaryDTOS);
    }

    @Override
    public void updateSalaryByCompanyUserId(SysSalaryDTO sysSalaryDTO) {
        SysSalary salary = BeanHelper.copyProperties(sysSalaryDTO, SysSalary.class);
        sysSalaryMapper.updateById(salary);
    }
}
